<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Relative Formats</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="datetime.formats.compound.html">Compound Formats</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="timezones.html">所支持的时区列表</a></div>
 <div class="up"><a href="datetime.formats.html">Supported Date and Time Formats</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="datetime.formats.relative" class="section">
  <h2 class="title">Relative Formats</h2>

  <p class="para">
   This page describes the different relative date/time formats that the
   <span class="function"><a href="function.strtotime.html" class="function">strtotime()</a></span>, <a href="class.datetime.html" class="classname">DateTime</a> and
   <span class="function"><a href="function.date-create.html" class="function">date_create()</a></span> parser understands.
  </p>

  <table class="doctable table">
   <caption><strong>Used Symbols</strong></caption>
   
    <thead>
     <tr>
      <th>Description</th>
      <th>Format</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><em>dayname</em></td>
      <td>&#039;sunday&#039; | &#039;monday&#039; | &#039;tuesday&#039; | &#039;wednesday&#039; | &#039;thursday&#039; |
      &#039;friday&#039; | &#039;saturday&#039; | &#039;sun&#039; | &#039;mon&#039; | &#039;tue&#039; | &#039;wed&#039; | &#039;thu&#039; | &#039;fri&#039; |
      &#039;sat&#039; | &#039;sun&#039;</td>
     </tr>

     <tr>
      <td><em>daytext</em></td>
      <td>&#039;weekday&#039; | &#039;weekdays&#039;</td>
     </tr>

     <tr>
      <td><em>number</em></td>
      <td>[+-]?[0-9]+</td>
     </tr>

     <tr>
      <td><em>ordinal</em></td>
      <td>&#039;first&#039; | &#039;second&#039; | &#039;third&#039; | &#039;fourth&#039; | &#039;fifth&#039; | &#039;sixth&#039; |
      &#039;seventh&#039; | &#039;eighth&#039; | &#039;ninth&#039; | &#039;tenth&#039; | &#039;eleventh&#039; | &#039;twelfth&#039; |
      &#039;next&#039; | &#039;last&#039; | &#039;previous&#039; | &#039;this&#039;</td>
     </tr>

     <tr>
      <td><em>reltext</em></td>
      <td>&#039;next&#039; | &#039;last&#039; | &#039;previous&#039; | &#039;this&#039;</td>
     </tr>

     <tr>
      <td><em>space</em></td>
      <td>[ \t]+</td>
     </tr>

     <tr>
      <td><em>unit</em></td>
      <td>((&#039;sec&#039; | &#039;second&#039; | &#039;min&#039; | &#039;minute&#039; | &#039;hour&#039; | &#039;day&#039; |
      &#039;fortnight&#039; | &#039;forthnight&#039; | &#039;month&#039; | &#039;year&#039;) &#039;s&#039;?) | &#039;weeks&#039; |
      <em>daytext</em></td>
     </tr>

    </tbody>
   
  </table>


  <table class="doctable table">
   <caption><strong>Day-based Notations</strong></caption>
   
    <thead>
     <tr>
      <th>Format</th>
      <th>Description</th>
      <th>Examples</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>&#039;yesterday&#039;</td>
      <td>Midnight of yesterday</td>
      <td>&quot;yesterday 14:00&quot;</td>
     </tr>

     <tr>
      <td>&#039;midnight&#039;</td>
      <td>The time is set to 00:00:00</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td>&#039;today&#039;</td>
      <td>The time is set to 00:00:00</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td>&#039;now&#039;</td>
      <td>Now - this is simply ignored</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td>&#039;noon&#039;</td>
      <td>The time is set to 12:00:00</td>
      <td>&quot;yesterday noon&quot;</td>
     </tr>

     <tr>
      <td>&#039;tomorrow&#039;</td>
      <td>Midnight of tomorrow</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td>&#039;back of&#039; <em>hour</em></td>
      <td>15 minutes past the specified hour</td>
      <td>&quot;back of 7pm&quot;, &quot;back of 15&quot;</td>
     </tr>

     <tr>
      <td>&#039;front of&#039; <em>hour</em></td>
      <td>15 minutes before the specified hour</td>
      <td>&quot;front of 5am&quot;, &quot;front of 23&quot;</td>
     </tr>

     <tr>
      <td>&#039;first day&#039; &#039; of&#039;?</td>
      <td>Sets the day of the first of the current month. This phrase is
      best used together with a month name following it.</td>
      <td>&quot;first day of January 2008&quot;</td>
     </tr>

     <tr>
      <td>&#039;last day&#039; &#039; of&#039;?</td>
      <td>Sets the day to the last day of the current month. This phrase is
      best used together with a month name following it.</td>
      <td>&quot;last day of next month&quot;</td>
     </tr>

     <tr>
      <td><em>ordinal</em> <em>space</em> <em>dayname</em> <em>space</em> &#039;of&#039;</td>
      <td>Calculates the <em>x</em>-th week day of the current month.</td>
      <td>&quot;first sat of July 2008&quot;</td>
     </tr>

     <tr>
      <td>&#039;last&#039; <em>space</em> <em>dayname</em> <em>space</em> &#039;of&#039;</td>
      <td>Calculates the <em class="emphasis">last</em> week day of the current month.</td>
      <td>&quot;last sat of July 2008&quot;</td>
     </tr>

     <tr>
      <td><em>number</em> <em>space</em>? (<em>unit</em> | &#039;week&#039;)</td>
      <td>Handles relative time items where the value is a number.</td>
      <td>&quot;+5 weeks&quot;, &quot;12 day&quot;, &quot;-7 weekdays&quot;</td>
     </tr>

     <tr>
      <td><em>ordinal</em> <em>space</em> <em>unit</em></td>
      <td>Handles relative time items where the value is text.</td>
      <td>&quot;fifth day&quot;, &quot;second month&quot;</td>
     </tr>

     <tr>
      <td>&#039;ago&#039;</td>
      <td>Negates all the values of previously found relative time items.</td>
      <td>&quot;2 days ago&quot;, &quot;8 days ago 14:00&quot;, &quot;2 months 5 days ago&quot;, &quot;2 months ago 5 days&quot;, &quot;2 days ago ago&quot;</td>
     </tr>

     <tr>
      <td><em>dayname</em></td>
      <td>Moves to the next day of this name.</td>
      <td>&quot;Monday&quot;</td>
     </tr>

     <tr>
      <td><em>reltext</em> <em>space</em> &#039;week&#039;</td>
      <td>Handles the special format &quot;weekday + last/this/next week&quot;.</td>
      <td>&quot;Monday next week&quot;</td>
     </tr>

    </tbody>
   
  </table>


  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Relative statements are always processed <em class="emphasis">after</em>
    non-relative statements. This makes &quot;+1 week july 2008&quot; and &quot;july
    2008 +1 week&quot; equivalent.
   </p>
   <p class="para">
    Exceptions to this rule are: &quot;yesterday&quot;, &quot;midnight&quot;, &quot;today&quot;, &quot;noon&quot;
    and &quot;tomorrow&quot;. Note that &quot;tomorrow 11:00&quot; and &quot;11:00 tomorrow&quot;
    are different. Considering today&#039;s date of &quot;July 23rd, 2008&quot; the
    first one produces &quot;2008-07-24 11:00&quot; where as the second one
    produces &quot;2008-07-24 00:00&quot;. The reason for this is that those
    five statements directly influence the current time.
   </p>
  </p></blockquote>

  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Observe the following remarks when the current day-of-week is the
    same as the day-of-week used in the date/time string. The current
    day-of-week could have been (re-)calculated by non-relative parts of
    the date/time string however.
   </p>
   <ol type="1">
    <li class="listitem">
     <span class="simpara">
      &quot;<em>dayname</em>&quot; does <em class="emphasis">not</em> advance to
      another day. (Example: &quot;Wed July 23rd, 2008&quot; means &quot;2008-07-23&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<em>number</em> <em>dayname</em>&quot; does
      <em class="emphasis">not</em> advance to another day. (Example: &quot;1
      wednesday july 23rd, 2008&quot; means &quot;2008-07-23&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<em>number</em> week <em>dayname</em>&quot; will
      first add the number of weeks, but does <em class="emphasis">not</em>
      advance to another day. In this case &quot;<em>number</em>
      week&quot; and &quot;<em>dayname</em>&quot; are two distinct blocks.
      (Example: &quot;+1 week wednesday july 23rd, 2008&quot; means &quot;2008-07-30&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<em>ordinal</em> <em>dayname</em>&quot;
      <em class="emphasis">does</em> advance to another day. (Example &quot;first
      wednesday july 23rd, 2008&quot; means &quot;2008-07-30&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<em>number</em> week <em>ordinal</em>
      <em>dayname</em>&quot; will first add the number of
      weeks, and then <em class="emphasis">advances</em> to another
      day. In this case &quot;<em>number</em> week&quot; and
      &quot;<em>ordinal</em> <em>dayname</em>&quot; are two
      distinct blocks. (Example: &quot;+1 week first wednesday july 23rd,
      2008&quot; means &quot;2008-08-06&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<em>ordinal</em> <em>dayname</em> &#039;of&#039; &quot;
      does <em class="emphasis">not</em> advance to another day. (Example:
      &quot;first wednesday of july 23rd, 2008&quot; means &quot;2008-07-02&quot; because
      the specific phrase with &#039;of&#039; resets the day-of-month to &#039;1&#039; and
      the &#039;23rd&#039; is ignored here).
     </span>
    </li>
   </ol>
   <p class="para">
    Also observe that the &quot;of&quot; in &quot;<em>ordinal</em>
    <em>space</em> <em>dayname</em>
    <em>space</em> &#039;of&#039; &quot; and &quot;&#039;last&#039; <em>space</em>
    <em>dayname</em> <em>space</em> &#039;of&#039; &quot; does
    something special.
   </p>
   <ol type="1">
    <li class="listitem">
     <span class="simpara">
      It sets the day-of-month to 1.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<em>ordinal</em> <em>dayname</em> &#039;of&#039; &quot; does
      <em class="emphasis">not</em> advance to another day. (Example: &quot;first
      tuesday of july 2008&quot; means &quot;2008-07-01&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<em>ordinal</em> <em>dayname</em> &quot;
      <em class="emphasis">does</em> advance to another day. (Example: &quot;first
      tuesday july 2008&quot; means &quot;2008-07-08&quot;, see also point 4 in the
      list above).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;&#039;last&#039; <em>dayname</em> &#039;of&#039; &quot; takes the last
      <em>dayname</em> of the current month. (Example: &quot;last
      wed of july 2008&quot; means &quot;2008-07-30&quot;)
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;&#039;last&#039; <em>dayname</em>&quot; takes the last
      <em>dayname</em> from the current day. (Example: &quot;last
      wed july 2008&quot; means &quot;2008-06-25&quot;; &quot;july 2008&quot; first sets the
      current date to &quot;2008-07-01&quot; and then &quot;last wed&quot; moves to the
      previous Wednesday which is &quot;2008-06-25&quot;).
     </span>
    </li>
   </ol>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Relative month values are calculated based on the length of months that
    they pass through. An example would be &quot;+2 month 2011-11-30&quot;, which would
    produce &quot;2012-01-30&quot;. This is due to November being 30 days in length, and
    December being 31 days in length, producing a total of 61 days.
   </p>
  </p></blockquote>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="datetime.formats.compound.html">Compound Formats</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="timezones.html">所支持的时区列表</a></div>
 <div class="up"><a href="datetime.formats.html">Supported Date and Time Formats</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
